function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	// 窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	// 弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}

$(function() {
	$(".pop_box").easydrag();
	$(".pop_box").setHandler(".pop_box .p_head");
});


function popadd()
{
	if(!RolePowerManager())
	{
		return;
	}
	popupDiv('add_div');
}
function clickEditRewAndPun(id, div_id) {
	RewAndPunManager.getAllRewAndPunType(function(data) {

		for ( var i = 0; i < data.length; i++) {
			$("#editAndPunType").append(
					"<option value='" + data[i].id + "'>" + data[i].type
							+ "</option>");
		}
		});
	
	RewAndPunManager.getRewAndPunById(id,function(data2)
			{
				$("#reid").val(data2.id);
				$("#empname").html(data2.emp.name);
				$("#edittitle").val(data2.title);
				$("#editAndPunType").val(data2.rewAndPunType.id);
				$("#content").val(data2.content);
				$("#editmoney").val(data2.money);
			});
	popupDiv(div_id);
}

function addRewAndPun() {

	
	
	var empno = $("#empno_add").val();
	
	var title = $("#title_add").val();
	var rewAndPunType = $("#rewAndPunType_add").val();
	var time = $("#time_add").val();
	var content = $("#content_add").val();
	var money = $("#money_add").val();

	if (empno && title && rewAndPunType && time &&  content && money) {
	
		RewAndPunManager.addRewAndPun(title , empno , rewAndPunType , time ,  content , money, function(data) {
					if (data) {
						alert("增加成功");
						location.reload("/GetAllRewAndPunServlet");
					} else {
						alert("增加失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function updateRewAndPun(id) {
	
	if(!RolePowerManager())
	{
		return;
	}
	var reid=$("#reid").val();
	var edittitle=$("#edittitle").val();
	var editAndPunType=$("#editAndPunType").val();
	var content=$("#content").val();
	var editmoney=$("#editmoney").val();
	if (edittitle&& editAndPunType && content && editmoney && editmoney&&reid)
	{
		RewAndPunManager.updateRewAndPun(reid,edittitle,editAndPunType,content,editmoney,function(data)
				{
						if(data)
						{
							alert("修改成功");
							location.reload("/GetAllRewAndPunServlet");
						}
						else
						{
							alert("修改失败");
						}
				});
	}else
	{
		alert("有必填项未填！");
	}
	
	
	//var empid = $("#empid_edit").val();
	/*var title = $("#title_edit").val();
	var rewAndPunType = $("#rewAndPunType_edit").val();
	var time = $("#time_edit").val();
	var content = $("#content_edit").val();
	var money = $("#money_edit").val();
	var id = $("#dossierid").val();	

	if (empid && title && rewAndPunType && time &&  content && money) {
		RewAndPunManager.updateRewAndPun(id, empid , title , rewAndPunType , time ,  content , money, function(data) {
					if (data) {
						alert("修改成功");
						location.reload("/GetAllRewAndPunServlet");
					} else {
						alert("修改失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}*/
}

function deleteRewAndPun(id) {
	if(!RolePowerManager())
	{
		return;
	}
	if(!confirm("是否确定删除 ？"))
	{
		return;
	}
	
	RewAndPunManager.deleteById(id, function(data) {
		if (data) {
			alert("修改成功");
			location.reload("/GetAllRewAndPunServlet");
		} else {
			alert("修改失败");
		}
	});
}

function getempname()
{
	RewAndPunManager.getEmpByEmpno($("#empno_add").val(),function(data)
			{
				if(data.name)
				$("#addempname").html(data.name);
				else
				{
					$("#addempname").html("未找到该员工");
				}
			});
		
}
$(function()
		{
	RewAndPunManager.getAllRewAndPunType(function(data) {

		for ( var i = 0; i < data.length; i++) {
			$("#rewAndPunType_add").append(
					"<option value='" + data[i].id + "'>" + data[i].type
							+ "</option>");
		}
		});
		});


function search2()
{
	
	$("#searchform").submit();
}



function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="GetRewAndPunServlet?pageSize="+pageSize;
}